package com.uchiha.nova.mainService.wrapper;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.uchiha.nova.core.tool.support.BaseEntityWrapper;
import com.uchiha.nova.core.tool.node.ForestNodeMerger;
import com.uchiha.nova.core.model.entity.OilUserEntity;
import com.uchiha.nova.core.model.vo.OilUserVO;
import com.uchiha.nova.mainService.service.IOilUserService;
import com.uchiha.nova.core.tool.util.SpringUtil;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**
 * 业务人员账号 包装类,返回视图层所需的字段
 *
 * @author Uchihashiamu
 */
public class OilUserWrapper extends BaseEntityWrapper<OilUserEntity, OilUserVO>  {
  
  IOilUserService oilUserService = SpringUtil.getBean(IOilUserService.class);
  
	public static OilUserWrapper build() {
		return new OilUserWrapper();
 	}

	@Override
	public OilUserVO entityVO(OilUserEntity oilUserEntity) {
		OilUserVO oilUserVO = new OilUserVO();
		BeanUtil.copyProperties(oilUserEntity, oilUserVO);
		List<String> list = new ArrayList<>();
		if(ObjectUtil.isNotEmpty(oilUserVO.getProvinceCode())){
			list.add(oilUserVO.getProvinceCode());
		}
		if(ObjectUtil.isNotEmpty(oilUserVO.getCityCode())){
			list.add(oilUserVO.getCityCode());
		}
		if(ObjectUtil.isNotEmpty(oilUserVO.getAreaCode())){
			list.add(oilUserVO.getAreaCode());
		}

		return oilUserVO;
	}
	public List<OilUserVO> listVO(List<OilUserEntity> list) {
		List<OilUserVO> collect = list.stream().map(item -> {
            OilUserVO oilUserVO = new OilUserVO();
		    BeanUtil.copyProperties(item, oilUserVO);			
			return oilUserVO;
		}).collect(Collectors.toList());
		return collect;
    // return ForestNodeMerger.merge(collect);
	}
  
  	@Override
	public IPage<OilUserVO> pageVO(IPage<OilUserEntity> pages) {
		IPage<OilUserVO> page = pages.convert(item->{
            OilUserVO oilUserVO = new OilUserVO();
		    BeanUtil.copyProperties(item, oilUserVO);
			List<String> list = new ArrayList<>();
			if(ObjectUtil.isNotEmpty(oilUserVO.getProvinceCode())){
				list.add(oilUserVO.getProvinceCode());
			}
			if(ObjectUtil.isNotEmpty(oilUserVO.getCityCode())){
				list.add(oilUserVO.getCityCode());
			}
			if(ObjectUtil.isNotEmpty(oilUserVO.getAreaCode())){
				list.add(oilUserVO.getAreaCode());
			}
			oilUserVO.setDataAuth(list);
			return oilUserVO;
		});
		return page;
	}
}
